package com.ycfmedical.bed.ui;

import java.util.ArrayList;
import java.util.List;

import com.bilibili.magicasakura.widgets.TintToolbar;
import com.ycfmedical.bed.R;
import com.ycfmedical.bed.base.BaseMenuActivity;
import com.ycfmedical.bed.present.EntertainPresenter;
import com.ycfmedical.bed.ui.fragment.MusicFragment;
import com.ycfmedical.bed.ui.fragment.VideoListFragment;
import com.ycfmedical.bed.ui.fragment.VideoSingleFragment;
import com.ycfmedical.bed.ui.fragment.WebFragment;
import com.ycfmedical.bed.utils.ResourceUtil;

import android.app.Activity;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;

import butterknife.BindView;
import cn.droidlover.xdroidmvp.base.XFragmentAdapter;
import cn.droidlover.xdroidmvp.router.Router;

/**
 * Created by Egoist on 2017/1/19.
 */

public class EntertainActivity extends BaseMenuActivity
{

    @BindView(R.id.entertain_tabs)
    TabLayout tabLayout;

    @BindView(R.id.entertain_viewpager)
    ViewPager viewPager;

    List<Fragment> fragmentList = new ArrayList<>();

    @BindView(R.id.toolbar)
    TintToolbar toolbar;

    private String[] titles = {ResourceUtil.getResources().getString(R.string.entertain_tab_music),
        ResourceUtil.getResources().getString(R.string.entertain_tab_video),
        ResourceUtil.getResources().getString(R.string.entertain_tab_web) };

    XFragmentAdapter mAdapter;

    @Override
    public void initData(Bundle savedInstanceState)
    {
        initViewPager();
    }

    @Override
    public void initToolbar()
    {
        super.initToolbar();
        getToolbarTitle().setText(ResourceUtil.getResources().getString(R.string.entertain));
    }

    private void initViewPager()
    {

        fragmentList.clear();
        fragmentList.add(MusicFragment.newInstance());
        fragmentList.add(VideoSingleFragment.newInstance());
        fragmentList.add(WebFragment.newInstance());
        if (mAdapter == null)
        {
            mAdapter = new XFragmentAdapter(getSupportFragmentManager(), fragmentList, titles);
        }
        viewPager.setAdapter(mAdapter);
        viewPager.setOffscreenPageLimit(3);

        tabLayout.setupWithViewPager(viewPager);
    }

    @Override
    public int getOptionsMenuId()
    {
        return R.menu.menu_main;
    }

    @Override
    public int getLayoutId()
    {
        return R.layout.activity_entertain;
    }

    @Override
    public EntertainPresenter newP()
    {
        return new EntertainPresenter(context);
    }

    public static void launch(Activity activity)
    {
        Router.newIntent(activity).to(EntertainActivity.class).launch();
    }
}
